package com.csun.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;
/**
 * @ClassName: ReponseUtil.java
 * @Description:TODO
 * @author danjinsong danjingsong@dragonwake.cn
 * @date 2017年2月17日下午4:25:12
 * 
 */
public class ResponseKit {
	/**
	 * 写 json
	 * @param response
	 * @param res
	 */
	public static void write(HttpServletResponse response,Object res){
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.println(res.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.flush();
			out.close();
		}
	}
	/**
	 * 简单返回 成功或者失败
	 * @param response
	 * @param flag
	 */
	public static void write(HttpServletResponse response,String flag){
		JSONObject res = new JSONObject();
		res.put(flag.toString(), true);
		write(response, res);
	}
}
